import javax.print.DocFlavor;

public class Leetcode278 {
    public static void main(String[] args) {
        System.out.println(firstBadVersion(2126753390));
    }

    public static int firstBadVersion(int n) {
        if (n == 1) {
            return 1;
        }

        int start = 1;
        int end = n;
        while (start < end) {
            int middle = (end - start) / 2 + start;

            if (isBadVersion(middle)) {
                end = middle;
            } else {
                start = middle + 1;
            }
        }

        return start;
    }

    public static boolean isBadVersion(int version) {
        return version >= 1702766719;
    }
}
